package com.newland.mesdk.demo.device;

import android.os.Handler;

import com.newland.mtype.ConnectionCloseEvent;
import com.newland.mtype.conn.DeviceConnParams;
import com.newland.mtype.event.DeviceEventListener;
import com.newland.mesdk.demo.activity.BaseActivity;
import com.newland.mesdk.demo.interfaceimpl.DeviceControllerInterfaceImpl;
import com.newland.mesdk.demo.moduleinterface.DeviceControllerInterface;
import com.newland.mesdk.demo.util.Const.MessageTag;

/**
 * Created by YJF 
 * 初始化设备控制器
 */
public class ME3xDeviceDriver {
	private BaseActivity baseActivity;
	private DeviceControllerInterface controller;

	public ME3xDeviceDriver(BaseActivity baseActivity) {
		this.baseActivity = baseActivity;
	}

	public DeviceControllerInterface initMe3xDeviceController(String driverPath, DeviceConnParams params) {
		controller = DeviceControllerInterfaceImpl.getInstance(driverPath);
		controller.init(baseActivity, driverPath, params, new DeviceEventListener<ConnectionCloseEvent>() {
			@Override
			public void onEvent(ConnectionCloseEvent event, Handler handler) {
				if (event.isSuccess()) {
					baseActivity.showMessage("设备被客户主动断开！", MessageTag.NORMAL);
				}
				if (event.isFailed()) {
					baseActivity.showMessage("设备链接异常断开！", MessageTag.ERROR);
				}
			}

			@Override
			public Handler getUIHandler() {
				return null;
			}
		});
		return controller;
	}

}
